
#pragma once

#include <string>

#include "topdbs_base_connection.hpp"
#include "mysql_common.hpp"

namespace topdbs
{
	class mysql_connection 
		: public topdbs_base_connection
	{
	private:
		MYSQL* m_pConnection;
		std::string m_host;
		int m_port;
		std::string m_user;
		std::string m_pass;
		std::string m_dbname;

		bool m_isTransaction;
		bool m_isConnected;	
	public:
		mysql_connection();
		virtual ~mysql_connection(); 

		//! Opens the connection to a data source.
		virtual int  connect(
			eDBSClient_t dbsClientType,
			const string& dbString,
			const string& user=string(),
			const string& pass=string(),
			void* pOption = NULL );

		//! Returns the connection state for a particular connection object.	
		virtual bool isConnected() override;
		virtual int  reConnect() override;
		//! Disconnects the connection from the database.
		virtual int  disConnect() override;	
		//! Begin transactions.
		virtual int  begin() override;
		//! Commits transactions.
		virtual int  commit() override;
		//! Rollback transactions.
		virtual int  rollback() override;
		//! Returns transactions.
		virtual bool isTransaction() override;
		//! Sets the connection to be committed automatically.
		virtual int  autoCommit(bool on = true) override;
		//Returns the native connection
		virtual void*  getConnection() override;
		//Returns the current this
		virtual void* from_this() override;
		//! Sets the connection lock wait time
		virtual int  lockwait() override; 

	private:
		MYSQL* connection_create( );
		int execute(const string& sCommandText );
	}; 
}

